using JaegerDemo.DService.Host.EventHandlers;
using JaegerDemo.DService.Host.Models;
using JaegerDemo.Shared;
using JaegerDemo.Shared.Options;
using MassTransit;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddOpenTracing();
var jaegerOptions = builder.Configuration.GetSection(JaegerOptions.Default).Get<JaegerOptions>();
builder.Services.AddJaegerTracer(jaegerOptions, builder.Environment.ApplicationName);
var rabbitMQOptions = builder.Configuration.GetSection(RabbitMQOptions.Default).Get<RabbitMQOptions>();
builder.Services.AddMasstransitEventBus(rabbitMQOptions, new MasstransitExtensions.EventBusConfigures()
{
    MasstransitConfigure = x =>
    {
        x.AddConsumer<ValueCreatedIntegrationEventHandler>();
    },
    RabbitMQConfigure = (context, cfg) =>
    {
        var queueName = "events-valuecreated";
        cfg.ReceiveEndpoint(queueName, e =>
        {
            e.ConfigureConsumer<ValueCreatedIntegrationEventHandler>(context);
        });
    }
});
builder.Services.AddDbContext<DServiceDbContext>();
var app = builder.Build();

if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();